<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        let arr=["张三","安小鸟","嬛嬛","沈眉庄"];
        let [a,b,c,d]=arr; //解构赋值(完全解构)
        //声明的变量和用来赋值的数组项 个数相同，就是完全解构
        console.log(a,b,c,d);
        
        //不完全解构
        let arr1=["熹妃","乌拉那拉","敬妃","华妃"];
        let [e,f]=arr1;
        console.log(e,f);

        //设置缺省值
        let arr2=[1,2,5,8];
        let [a1,a2,,a3]=arr2;
        console.log(a1,a2,a3);

        //解构失败
        let arr3=[7,8,9];
        let [b1,b2,b3,b4]=arr3;
        console.log(b1,b2,b3,b4);  //7 8 9 undefined

        //解构默认值
        let arr4=[4,3,2];
        let [c1,c2,c3,c4="你好"]=arr4;
        console.log(c1,c2,c3,c4);
        //如果解构失败，c4就是默认值“你好”；
        // 如果有对应值给c4赋值，就是对应值，不使用默认值
    </script>
    
</body>
</html>